version: "3.8"

services:
  traefik:
    image: traefik:v2.4.8
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.swarmMode=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--api=true"
      - "--api.dashboard=true"
      - "--api.debug=true"
      - "--accesslog=true"
      - "--log=true"
      - "--log.filepath=/tmp/traefik.err.log"
      - "--accesslog.filepath=/tmp/traefik.access.log"
      - "--metrics.prometheus=true"
      - "--metrics.prometheus.buckets=0.100000, 0.300000, 1.200000, 5.000000"
      - "--metrics.prometheus.addEntryPointsLabels=true"
      - "--metrics.prometheus.addServicesLabels=true"
      - "--entryPoints.metrics.address=:8082"
      - "--metrics.prometheus.entryPoint=metrics"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
      - "8082:8082"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - "default"
    deploy:
      mode: replicated
      replicas: 1
      labels:
        - "traefik.enable=true"
        - "traefik.docker.network=default"
        - "traefik.http.services.traefik_traefik.loadbalancer.server.port=8080"
        # http 80
        - "traefik.http.routers.traefik-ui-80.rule=Host(`traefik.localhost.com`)" 
        - "traefik.http.routers.traefik-ui-80.entrypoints=web"
        # https 443
        - "traefik.http.middlewares.redirect-https.redirectScheme.scheme=https"
      placement:
        constraints: [node.role == manager]
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s


networks:
  default:
    external:
      name: traefik_default